package carlyang;

class FinalTest {
	private int time = 0;

	public FinalTest() {
		time = 10;
	}

	@Override
	public String toString() {
		return "FinalTest time=" + time;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public void test() {
		FinalTest finalTest = new FinalTest();
		System.out.println(finalTest.toString());
		System.out.println(this.toString());
	}
}

final class FinalTest2 {
	public FinalTest2() {

	}

	public final static FinalTest finalTest = new FinalTest();
}

interface test {
	public static final int TEST = 1;

	public abstract void show();
}

class useTest implements test {
	public static final int TEST = 2;

	@Override
	public void show() {
		Out.println("Test=" + useTest.TEST);// 可以直接使用“父类”接口的域（字段），这里使用本类的域。
		Out.println("Test=" + test.TEST);// 使用接口（父类）的域。
	}
}

public class OtherTest {

	public OtherTest() {
		// TODO Auto-generated constructor stub
		System.out.println("OtherTest Constractor");
	}

	static {
		new OtherTest();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Out.println(FinalTest2.finalTest.toString());
		OtherTest otherTest = new OtherTest();
		FinalTest finalTest = new FinalTest();
		finalTest.test();
		new useTest().show();
		switchTest();
	}

	private static void switchTest() {
		// TODO Auto-generated method stub
		String string = "124";
		switch (string) {
		case "123":
			int a = 0;
			System.out.println("a="+a);
			break;
		case "124":
			a = 124;
			System.out.println("a="+a);
			break;

		default:
			break;
		}
	}

}

/*
 * final static usage different
 */
class TopLayer {
	final FinalTest finalTest;// final变量字段
								// 可以在非静态的地方（构造函数，构造代码块）初始化，但是只能且必须有一个地方初始化。
	public static final FinalTest finalTest2; // 只能在声明时初始化或静态代码块中初始化。两者选其一，因为final。
	public static int a = 0;// 静态变量初始化可以多个地方
	static {
		a = 1;
		finalTest2 = new FinalTest();// 此处初始化，在声明是不能初始化
	}
	{
		finalTest = new FinalTest();
		a = 2;
	}

	public TopLayer(FinalTest finalTest) {
		super();
		// TODO Auto-generated constructor stub
		// this.finalTest = finalTest;
	}

}
